home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Utilities Professional 1-1500
/
Utilities Professional 1-1500 (1994)(WPD)[!].iso
/
07511000
/
var0888.dms
/
var0888.adf
/
WoManD
/
man
/
C_Library
/
qsort
< prev
next >
Wrap
Text File
|
1992-09-19
|
2KB
|
65 lines
QSORT(1) C LIBRARY FUNCTIONS QSORT(1)
NAME
qsort - to quickly sort an array.
SYNOPSIS
qsort(const void *a_ptr, size_t n, size_t el_size,
int (*compar)(const void *, const void * ));
INCLUDE FILE
stdlib.h
DESCRIPTION
qsort() sorts the array pointed to by a_ptr in ascending order with
respect to the comparison function pointed to by compar. The
array must have n elements, each one stored in el_size bytes. The
function compar() takes as arguments two addresses of elements
of the array. It returns an int that is less than, equal to or
greater than zero, depending on whether the element pointed to
by its first argument is considered to be less than, equal to,
or greater than the element pointed to by its second argument.
qsort() is an implementation of the quicker-sort algorithm. It
sorts a table of data in place.
NOTES
The pointer to the base of the table should be of type
pointer-to-element, and cast to type pointer-to-void.
The comparison function need not compare every byte, so arbitrary data
may be contained in the elements in addition to the values being
compared.
SEE ALSO
bsearch().
EXAMPLE
The following program sorts a simple array:
static int intcompare(i,j)
int *i, *j;
{ return(*i - *j);
}
main()
{ int a[10];
int i;
a[0] = 9;
a[1] = 8;
a[2] = 7;
a[3] = 6;
a[4] = 5;
a[5] = 4;
a[6] = 3;
a[7] = 2;
a[8] = 1;
a[9] = 0;
qsort(a,10,sizeof(int),intcompare)
for (i=0; i<10; i++) printf(" %d",a[i]);
printf("\n");
}